package com.pds.web.category.controller;

import com.pds.common.annotation.Log;
import com.pds.common.core.controller.BaseController;
import com.pds.common.core.domain.R;
import com.pds.common.core.page.TableDataInfo;
import com.pds.common.enums.BusinessType;
import com.pds.web.category.entity.PdsCategory;
import com.pds.web.category.service.PdsCategoryService;
import com.pds.web.category.vo.CategoryStandardVO;
import com.pds.web.category.vo.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 检测项目类别表
 *
 * @author srf sunlightcs@gmail.com
 * @since 1.0.0 2024-02-29
 */
@RestController
@RequestMapping("/category")
@Api(tags="检测项目类别")
public class PdsCategoryController extends BaseController {
    @Resource
    private PdsCategoryService pdsCategoryService;

    /**
     * 分页查询项目类别
     *
     *   pageNum/pageSize分页字段
     *   筛选条件字段
     * @return 查询结果
     */
    @ApiOperation("分页查询项目类别")
    @GetMapping("/page")
    public TableDataInfo pageCategory(PdsCategory pdsCategory){
        startPage();
//        List<CategoryStandardVO> list = pdsCategoryService.selectList(pdsCategory);
        List<CategoryStandardVO> list = null;
        TableDataInfo dataTable = getDataTable(list);
        Integer count = pdsCategoryService.selectListCount(pdsCategory);
        dataTable.setTotal(count);
        return dataTable;
    }

    /**
     * 查询项目类别列表
     *
     *   筛选条件字段
     * @return 查询结果
     */
    @ApiOperation("查询项目类别列表")
    @GetMapping("/list")
    public R<Map> listCategory(@RequestParam("status") String status,
                               @RequestParam(name="organizationId",required = false) String organizationId){
        Map result = pdsCategoryService.selectList(status,organizationId);
        return R.ok(result);
    }

    /**
     * 根据ID查询项目类别
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("项目类别详情")
    @GetMapping("/queryById/{id}")
    public R<PdsCategory> queryCategoryById(@PathVariable("id")Long id) {
        return R.ok(pdsCategoryService.queryById(id));
    }

    /**
     * 创建项目类别
     * @param pdsCategory 记录
     * @return 项目类别
     */
    @ApiOperation("创建项目类别")
    @PostMapping("/add")
    @Log(title = "创建项目类别", businessType = BusinessType.INSERT)
    public R<PdsCategory> addCategory(@RequestBody PdsCategory pdsCategory){
        return R.ok(pdsCategoryService.insert(pdsCategory));
    }

    /**
     * 修改项目类别
     * @param pdsCategory 记录
     * @return 成功标识
     */
    @ApiOperation("修改项目类别")
    @PutMapping("/edit")
    public R<Boolean> editCategory(@RequestBody PdsCategory pdsCategory){
        return R.ok(pdsCategoryService.update(pdsCategory));
    }

    /**
     * 根据ID删除项目类别
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation("删除项目类别")
    @DeleteMapping("/delete")
    public R<Object> deleteCategoryById(@RequestParam Long id) {
        return R.ok(pdsCategoryService.deleteById(id));
    }


    /**
     * 查询当前登录用户检测机构的检测因子
     * @return 查询结果
     */
    @GetMapping("/getOrganizationCategory")
    public R getOrganizationCategory(){
        List<CategoryStandardVO> organizationCategory = pdsCategoryService.getOrganizationCategory();
        return R.ok(organizationCategory);
    }
}
